<?php
/**
 * 推送的
 * User: zhangwei
 * Date: 2017/6/14
 * Time: 14:24
 */

namespace Push\Controller;
use Common\Controller\FrontbaseController;

class MessageController extends FrontbaseController{
	public function _initialize() {
		parent::_initialize();
		\User\Lib\ImiLib::checkLogin($this); //检测用户登录状态
	}

	/**
	 * 推送列表
	 * @param string $type 说明：目前 weibo_praise 赞功能 | weibo_comment 评论功能 | meeting 聚会，多个以逗号分开，如：meeting,weibo_praise
	 * @author 张伟 2017-06-18
	 * @author Hongwei 2017-06-21 增加$type
	 * TODO 数量默认为空,APP默认传10条
	 */
	public function index ($type = '',$num = 10){
		// 判断 $type
		if($type){
			$types = explode(',',$type);
			$number = count($types);
			if($number==1){
				$where['type'] = $type;
			}else{
				$where['type'] =  array('in',$type); //多条件查询
			}
		}

		// 列表
		$list = D('Push')->order('time desc')->limit(0,$num)->where($where)->order('id desc')->select();
		// 返回
		if($list){
			foreach ($list as $key => $value){
				$list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
			};
			$assign['list']   = $list;
			$assign['status'] = 1;
		}else{
			$assign['error'] = 1;
			$assign['error_msg'] = '没有相关数据';
		}
		$this -> output($assign);
	}
}